#include "functionFitness.h"

//Cambiar la funcion de fitness acorde al ejercicio que se desee resolver
/*
double functionFitness(vector<bool> chromosome){
	double x = genotype2fenotype(chromosome,-512,1024);
	return (-x*sin(sqrt(fabs(x))) + 418.98); //Para que la salida sea positiva      //config=800.0
}
*/
double functionFitness(vector<bool> chromosome){
	double x = genotype2fenotype(chromosome,-5.12,10.24);
	return (1/(x*x + 1));       //config=0.999 (para que el fitness quede crec) - perfecto = 1
}

double genotype2fenotype(vector<bool> chromosome, double leftLimit, double sizeDomain){
	double x=0;
	unsigned int sizeChrom = chromosome.size();
	for(unsigned int i=0;i<sizeChrom;i++){
		if(chromosome[i]){
			x += pow(2,sizeChrom-i-1);
		}
	}
	x = leftLimit + x * sizeDomain / (pow(2,sizeChrom) - 1);
	return x;
}
vector<bool> fenotype2genotype(double xa, double leftLimit, double sizeDomain, int sizeChrom){
	int x = int ((xa - leftLimit) * (pow(2,sizeChrom) - 1) / sizeDomain);
	vector<bool> chromosome(sizeChrom);
	for (int i=0; i<sizeChrom; i++){
		chromosome[sizeChrom - i] = x % 2;
		x = int(x/2);
	}
	return chromosome;
}
